package org.example.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.example.bean.Orders;
import org.example.bean.Product;

import java.util.List;

public interface ProductMapper extends BaseMapper<Product> {
    @Select("select p.*,c.category_name\n" +
            "from product p\n" +
            "left join category c on p.category_id=c.category_id\n" +
            "where p.product_id=#{product_id}")
    @Results({
            //property需要严格对照bean类的信息
            @Result(column = "product_id", property = "product_id"),
            @Result(column = "category_id", property = "category_id"),
            @Result(column = "product_name", property = "product_name"),
            @Result(column = "main_url", property = "main_url"),
            @Result(column = "sub_url", property = "sub_url"),
            @Result(column = "description", property = "description"),
            @Result(column = "price", property = "price"),
            @Result(column = "original_price", property = "original_price"),
            @Result(column = "product_status", property = "product_status"),
            @Result(column = "category_name", property = "category_name")
    })
    Product selectProductById(@Param("product_id") Integer product_id);
}
